package com.caiyi.tips.user.mapper;

import com.caiyi.tips.user.DTO.SmsDTO;
import com.caiyi.tips.user.bean.SmsBean;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

@Component("smsMapper")
public interface SmsMapper {
    void checkYzm(SmsBean bean);

    @Update("update tb_bind_msg set icount=icount+1 where iverify=0 and cadddate>=sysdate-1 and " +
            "cphone=#{phone, jdbcType=VARCHAR} and crandom=#{random, jdbcType=VARCHAR} and itype=#{yzmType, jdbcType=INTEGER} and iusertype=#{userType, jdbcType=INTEGER}")
    int updateMsgCheckCount(SmsBean smsBean);

    @Update("update tb_bind_msg set iverify=1 where iverify=0 and cadddate>=sysdate-1 and " +
            "cphone=#{phone, jdbcType=VARCHAR} and crandom=#{random, jdbcType=VARCHAR} and itype=#{yzmType, jdbcType=INTEGER} and iusertype=#{userType, jdbcType=INTEGER}")
    int updateMsgVerify(SmsBean smsBean);

    @Insert("insert into tb_bind_msg\n" +
            "        (ibindid, cuserid, cphone, crandom, cadddate, iverify, itype, icount, iusertype)\n" +
            "        values\n" +
            "        (seq_bind_msg.nextval, '9188', #{phone, jdbcType=VARCHAR}, #{random, jdbcType=VARCHAR}, sysdate, 0, #{yzmType, jdbcType=INTEGER},\n" +
            "        #{count, jdbcType=INTEGER}, #{userType, jdbcType=INTEGER})")
    int insertBindMsg(SmsDTO dto);

    @Insert("        insert into tb_sms\n" +
            "        (ismsid,\n" +
            "        cphone,\n" +
            "        ccontent)\n" +
            "        values\n" +
            "        (seq_sms.nextval,\n" +
            "        #{phone,jdbcType=VARCHAR},\n" +
            "        #{content,jdbcType=VARCHAR})")
    int insertSms(SmsDTO dto);

    int checkInvalidMsg(SmsBean bean);
}
